﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.Composition;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;

namespace EIA.SLClient.ProjectManage
{
    [Export]
    public partial class MainPage : UserControl, SimpleMvvmToolkit.INotifyable
    {
        [Import(AllowRecomposition = false)]
        public IModuleManager ModuleManager;
        [Import]
        public IRegionManager RegionManager;

        public MainPage()
        {
            InitializeComponent();
            this.ProjectDetail.Visibility = System.Windows.Visibility.Collapsed;
            SimpleMvvmToolkit.MessageBus.Default.Register(EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.PROJECT_DETAIL_SHOW, this);
            SimpleMvvmToolkit.MessageBus.Default.Register(EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.PROJECT_DETAIL_HIDE, this);
            SimpleMvvmToolkit.MessageBus.Default.Register(EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.LOGIN_STAFF_IDENTIFIED, this);
            SimpleMvvmToolkit.MessageBus.Default.Register(EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.CHANGE_PASSWORD, this);
        }

        public void Notify(string token, object sender, SimpleMvvmToolkit.NotificationEventArgs e)
        {
            switch (token)
            {
                case EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.PROJECT_DETAIL_HIDE:
                    this.ProjectDetail.Visibility = System.Windows.Visibility.Collapsed;
                    break;
                case EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.PROJECT_DETAIL_SHOW:
                    this.ProjectDetail.Visibility = System.Windows.Visibility.Visible;
                    break;
                case EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.LOGIN_STAFF_IDENTIFIED:
                    ModuleManager.LoadModule("BasicModule");
                    ModuleManager.LoadModule("MembersModule");
                    ModuleManager.LoadModule("ProgressModule");
                    ModuleManager.LoadModule("ContractModule");
                    ModuleManager.LoadModule("BonusModule");
                    ModuleManager.LoadModule("FinancialModule");
                    ModuleManager.LoadModule("ApproveModule");
                    ModuleManager.LoadModule("StatisticModule");
                    break;
                case EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.LOGIN_SHOW:
                    RegionManager.RequestNavigate(EIA.SLClient.ProjectManage.Infrastructure.RegionNames.PopupRegion, typeof(LoginView).FullName);
                    break;
                case EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.CHANGE_PASSWORD:
                    RegionManager.RequestNavigate(EIA.SLClient.ProjectManage.Infrastructure.RegionNames.PopupRegion, typeof(ChangePasswordView).FullName);
                    break;
            }
        }
    }
}
